<template>
  <div>
    <FormPanel ref="formPanel" :list="topFilterList" :cols="4" :labelWidth="90" formType="add" :isSubmitBtn="false" columnsRef="asdasdxkpjxscxTable" @formChange="searchCustomerChoice"></FormPanel>
    <div class="confirm-button-style" style="text-align:center;">
      <el-button size="small" type="primary" @click="queryClick">查询</el-button>
      <!-- <el-button size="small" @click="resetClick" type="primary">重 置</el-button> -->
    </div>
    <FilterTable
      ref="table"
      columnsRef="partPartOutboundAdjustOutboundCustomerChoice"
      height="100px"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      selectionType="single"
    ></FilterTable>

    <div class="confirm-button-style" style="text-align:center;margin-top:20px;">
      <el-button @click="closeDrawer(1)">取 消</el-button>
      <el-button type="primary" @click="closeDrawer(2)">确 定</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { searchAdjustOrder } from '@/api/part/partOutbound/adjustOutbound';

export default {
  name: 'customerChoice',
  mixins: [dictionary],
  data() {
    return {
      topFilterList: this.createTopFilterList(),
      columns: this.createTablelist(),
      fetchApi: searchAdjustOrder,
      fetchParams: { xhrAbort: false } // 调用数据
    };
  },
  mounted() {},
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '客户代码',
          fieldName: 'customerCade'
        },
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'customerName'
        },
        {
          type: 'SELECT',
          label: 'OME下发',
          fieldName: 'OME',
          itemList: this.createDictList('1004')
        },
        {
          type: 'SELECT',
          label: '客户类型',
          fieldName: 'customerType',
          itemList: this.createDictList('4045')
          // itemList:[{ text: '是', value: 10571001 }, { text: '否', value: 0 }]
        }
      ];
    },
    createTablelist() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          },
          sorter: true
        },
        {
          title: '客户代码',
          dataIndex: 'customerCode',
          width: 80,
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户名称',
          dataIndex: 'customerName',
          width: 80,
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户拼音',
          dataIndex: 'customerPY',
          width: 80,
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户类别',
          dataIndex: 'customerType',
          width: 80,
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '加价率',
          dataIndex: 'limitedPrice',
          showOverflowTooltip: true
        },
        {
          title: '订货周期',
          dataIndex: 'marketingPrice',
          showOverflowTooltip: true
        },
        {
          title: '最大库存',
          dataIndex: 'maxInventory',
          showOverflowTooltip: true
        },
        {
          title: '最小库存',
          dataIndex: 'minInventory',
          showOverflowTooltip: true
        },
        {
          title: '账面库存',
          dataIndex: 'bookInventory',
          showOverflowTooltip: true
        },
        {
          title: '可用库存',
          dataIndex: 'availableInventory',
          showOverflowTooltip: true
        },
        {
          title: '借进数量',
          dataIndex: 'borrowNum',
          showOverflowTooltip: true
        },
        {
          title: '借出数量',
          dataIndex: 'lendNum',
          showOverflowTooltip: true
        },
        {
          title: '锁定量',
          dataIndex: 'lockingNum',
          showOverflowTooltip: true
        },
        {
          title: '替代配件',
          dataIndex: 'replacementParts',
          width: 80,
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '替代件库存',
          dataIndex: 'replacementInventory',
          width: 80,
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配件类别',
          dataIndex: 'accessoriesCategory',
          width: 80,
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '单位',
          dataIndex: 'unit'
        },
        {
          title: '配件车型组集',
          dataIndex: 'fittingsOfMachine',
          width: 80,
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    // 确定与取消
    closeDrawer(type) {
      if (type == 1) {
        this.$emit('close', true);
      } else {
        if (!this.selectedRows.length) {
          return this.$notify({
            title: '提示信息',
            message: '请选择一条数据',
            type: 'warning'
          });
        }
        if (this.selectedRows.some(x => Number(x.COUNT) <= 0)) {
          return this.$notify({
            title: '提示信息',
            message: '请选择一条数据',
            type: 'warning'
          });
        }
        this.$emit('saveDialog', this.selectedRows);
      }
    },
    searchCustomerChoice(val) {
      console.log('打印了', val);
      const params = Object.assign({}, val, { offset: 0, xhrAbort: false });
      this.fetchParams = params;
    },
    // 查询
    queryClick() {
      this.$refs.formPanel.SUBMIT_FORM();
    },

    // 选中
    selectChange(rows) {
      this.selectedRows = rows;
    }
  }
};
</script>
<style lang="less" scoped></style>
